<?php

namespace App\Http\Controllers\Home\time;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class TimeController extends Controller
{

    // time()留言显示
    public function index()
    {
        $content = DB::table('message') -> get();
        $id = session()->get('master') -> id;
         $data = DB::table('users')
            -> select('users.*', 'user_info.hd_pic','user_info.signature')
            -> leftJoin('user_info', 'users.id', '=' ,'user_info.id')
            -> where('users.id', '=', $id)
            -> get();
        // dd($data);
        // dd($data);
        return view('Home.time.index', ['data' => $data, 'content' => $content]);
    }

    // text() 发布留言板方法
    public function text()
    {

        return view('Home.time.add');
    }

    // 留言板提交过来的数据
    public function doadd(Request $request)
    {

        $data = $request -> except('_token');
        $time = date('Y-m-d H:i:s');
        $data['created_at'] = $time;
        $data['updated_at'] = $time;
        $data['uid'] = session()->get('master') -> id;
        // dd($data);
         $res = DB::table('message') -> insert($data);
        if($res)
        {
            return redirect('/timeline') -> with(['info' => '发表成功']);
        }else
        {
            return back() -> with(['info' => '发表失败']);
        }
    }
}
